package com.letv.core.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.view.inputmethod.InputMethodManager;

import com.letv.android.sdk.R;
import com.letv.component.upgrade.utils.LetvUtil;
import com.letv.core.db.PreferencesManager;

import java.lang.reflect.InvocationTargetException;

public class DialogUtil {

//	private static void showPopWin(View anchor, int layoutID, String text,
//			boolean isCancelOutSide) {
//
//		Context context = anchor.getContext();
//		LayoutInflater inflater = LayoutInflater.from(context);
//		View viewRoot = inflater.inflate(layoutID, null);
//		((TextView) viewRoot.findViewById(R.id.toast_text)).setText(text);
//		((ProgressBar) viewRoot.findViewById(R.id.progress))
//				.setVisibility(isCancelOutSide ? View.GONE : View.VISIBLE);
//		final PopupWindow popWin = new PopupWindow(viewRoot,
//				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//		popWin.setOutsideTouchable(isCancelOutSide);
//		popWin.setBackgroundDrawable(new ColorDrawable(0));
//		popWin.showAtLocation(anchor, Gravity.CENTER, 0, 0);
//		new Handler(anchor.getContext().getMainLooper()).postDelayed(
//				new Runnable() {
//
//					@Override
//					public void run() {
//						if (popWin.isShowing()) {
//							popWin.dismiss();
//						}
//					}
//				}, 2000);
//	}
	
	public static boolean canDownload3g(Activity activity) {
		if (activity == null) {
			Log.e("", " canDownload3g  activity == null ");
			return true;
		}
		if (NetworkUtils.isNetworkAvailable(activity)) {
			if (!NetworkUtils.isWifi(activity)) {
				if (!PreferencesManager.getInstance().isAllowMobileNetwork()) {
					call(activity, activity.getResources().getString(R.string.dialog_3g_download), new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// stub
							dialog.dismiss();
						}
					});
					return false;
				}
			}
		}
		return true;
	}

	static Handler handler;

	/**
	 * 解决 toast 退出不消失，排查原因可能与退出时消息队列未及时处理消息有关，解决法案，创建一个新的looper
	 * 
	 * @param txtId
	 */
//	public static void showToast2(final int txtId) {
//		UIsUtils.showToast(BaseApplication.instance, txtId);
//	}

	public static void call(Activity activity, int messageId,
			DialogInterface.OnClickListener yes,
			DialogInterface.OnClickListener no) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setPositiveButton(R.string.dialog_default_ok, yes)
				.setNegativeButton(R.string.dialog_default_no, no).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			try {
				dialog.show();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * public static void showToast(int txtId) { mToast =
	 * Toast.makeText(LetvApplication.getInstance(), txtId, Toast.LENGTH_SHORT);
	 * mToast.setText(txtId); mToast.setGravity(Gravity.CENTER, 0, 0);
	 * mToast.setDuration(Toast.LENGTH_SHORT); mToast.show(); }
	 * 
	 * /** 隐藏键盘输入法
	 * 
	 * @param mActivity
	 */
	public static void hideSoftkeyboard(Activity mActivity) {
		if (null != mActivity && null != mActivity.getCurrentFocus()) {
			InputMethodManager mInputMethodManager = (InputMethodManager) mActivity
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			if (null != mInputMethodManager) {
				mInputMethodManager.hideSoftInputFromWindow(mActivity
						.getCurrentFocus().getWindowToken(),
						InputMethodManager.HIDE_NOT_ALWAYS);
			}
		}
	}

	// private static LetvToast mLetvToast = null;
	//
	// public static void setFullscreenCompatibility(Activity activity) {
	// if ("Galaxy Nexus".equals(Build.MODEL.trim()));
	// try {
	// Object localObject1 = View.class.getDeclaredField(
	// "SYSTEM_UI_FLAG_HIDE_NAVIGATION").get(View.class);
	// Class[] localObject2 = new Class[1];
	// localObject2[0] = Integer.TYPE;
	// Method localMethod = View.class.getMethod("setSystemUiVisibility",
	// localObject2);
	// View view = activity.getWindow().getDecorView();
	// Object[] arrayOfObject = new Object[1];
	// arrayOfObject[0] = localObject1;
	// localMethod.invoke(view, arrayOfObject);
	// return;
	// } catch (InvocationTargetException localInvocationTargetException) {
	// } catch (NoSuchMethodException localNoSuchMethodException) {
	// } catch (IllegalAccessException localIllegalAccessException) {
	// } catch (NoSuchFieldException localNoSuchFieldException) {
	// } catch (IllegalArgumentException localIllegalArgumentException) {
	// } catch (SecurityException localSecurityException) {
	// } catch (Exception e) {
	// }
	//

	//
	// public static void setFullscreenCompatibility(Activity activity) {
	// // if ("Galaxy Nexus".equals(Build.MODEL.trim()));
	// // try {
	// // Object localObject1 = View.class.getDeclaredField(
	// // "SYSTEM_UI_FLAG_HIDE_NAVIGATION").get(View.class);
	// // Class[] localObject2 = new Class[1];
	// // localObject2[0] = Integer.TYPE;
	// // Method localMethod = View.class.getMethod("setSystemUiVisibility",
	// // localObject2);
	// // View view = activity.getWindow().getDecorView();
	// // Object[] arrayOfObject = new Object[1];
	// // arrayOfObject[0] = localObject1;
	// // localMethod.invoke(view, arrayOfObject);
	// // return;
	// // } catch (InvocationTargetException localInvocationTargetException) {
	// // } catch (NoSuchMethodException localNoSuchMethodException) {
	// // } catch (IllegalAccessException localIllegalAccessException) {
	// // } catch (NoSuchFieldException localNoSuchFieldException) {
	// // } catch (IllegalArgumentException localIllegalArgumentException) {
	// // } catch (SecurityException localSecurityException) {
	// // } catch (Exception e) {
	// // }
	// }
	//
	// public static void playCheck(final Activity activity , int albumId ,
	// int
	// type) {
	// if (PreferencesManager.getInstance().isLogin()) {
	//
	// } else {
	// if (payType == 1 || payType == 2) {
	// call(activity, R.string.dialog_vip_login, R.string.dialog_login,
	// R.string.dialog_cancel,
	// new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// LoginActivity.launchForResult(activity, 123);
	// }
	// }, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// } else if (payType == 0) {
	// call(activity, R.string.dialog_buy_login, R.string.dialog_login,
	// R.string.dialog_cancel,
	// new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// LoginActivity.launchForResult(activity, 123);
	// }
	// }, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// }
	//
	// }
	// }
	//
	// /**
	// * 需要付费影片，弹出框
	// * */
	// public static void showNewLogin(final Activity activity, int payType,
	// final String name,
	// final int albumId, final String date, final double price) {
	// LogInfo.log("payType=" + payType + " name=" + name + " albumId=" +
	// albumId + " date="
	// + date + "  price=" + price);
	//
	// if (PreferencesManager.getInstance().isLogin()) {
	// if (payType == 1 || payType == 2) {
	// call(activity, R.string.dialog_vip_buy, R.string.dialog_buyvip,
	// R.string.dialog_cancel, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// VipGoodsActivity.launch(activity, albumId);
	// }
	// }, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// } else if (payType == 0) {
	// call(activity, R.string.dialog_buy_buy, R.string.dialog_buy,
	// R.string.dialog_cancel, new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// PayCentreActivity.launch(activity, "0", name, date, price, albumId,
	// null);
	// }
	// }, new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// }
	// } else {
	// if (payType == 1 || payType == 2) {
	// callDialogMsgPosNeg(activity, DialogMsgConstantId.SIX_ZERO_TWO_CONSTANT,
	// R.string.dialog_login, R.string.dialog_cancel,
	// new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// LoginActivity.launchForResult(activity, 123);
	// }
	// }, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// } else if (payType == 0) {
	// call(activity, R.string.dialog_buy_login, R.string.dialog_login,
	// R.string.dialog_cancel, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// LoginActivity.launchForResult(activity, 123);
	// }
	// }, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// } else {
	// call(activity, R.string.dialog_buy_login, R.string.dialog_login,
	// R.string.dialog_cancel, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// LoginActivity.launchForResult(activity, 123);
	// }
	// }, new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	//
	// }
	// });
	// }
	//
	// }
	// }
	//
	// public static void showLogin(final Activity activity, int payType, final
	// String name,
	// final int albumId, final String date, final double price) {
	// /**
	// * payDate string 服务期限
	// * singlePrice string 单片价格
	// * allowMonth string 1:单点且支持包月;0:仅单点;2:仅支持包月;
	// *
	// * chargetype string 0:点播;1:点播且包月;2:包月
	// * chargeflatform string 价格,默认为0，表示对应平台无数据(平台:phone,pad)
	// * validDays string 服务期限
	// *
	// * UIs.showLogin(AlbumDetailActivity.this, album.getAllowmonth(),
	// * album.getTitle(), album.getAid(), album.getPaydate(),
	// * album.getSingleprice());
	// */
	// if (payType == -1 || date==null) {
	// new RequestAlbumPayInfoTask(activity, albumId + "", new UpdateAlbumInfo()
	// {
	// @Override
	// public void updateAlbumInfo(AlbumPayInfo mAlbumPayInfo) {
	// showNewLogin(activity, mAlbumPayInfo.getChargeflatform(), name, albumId,
	// mAlbumPayInfo.getValidDays() + "", mAlbumPayInfo.getChargeflatform());
	// }
	// }, true).start();
	// }else {
	// showNewLogin(activity, payType, name, albumId,
	// date, price);
	// }
	// }
	//

	private static LetvCommonDialog mCommonDialog;

	/**
	 * 显示只有一个标题两个按钮的对话框
	 * 
	 * @param context
	 * @param title
	 * @param leftText
	 * @param rightText
	 */
	public static void showDialog(Activity context, CharSequence title,
			CharSequence leftText, CharSequence rightText,
			DialogInterface.OnClickListener leftListener,
			DialogInterface.OnClickListener rightListener) {
		showDialog(context, title, "", leftText, rightText, leftListener, rightListener);
	}
	
	
	public static void showDialog(Activity context, CharSequence title,CharSequence content,
			CharSequence leftText, CharSequence rightText,
			DialogInterface.OnClickListener leftListener,
			DialogInterface.OnClickListener rightListener) {
		if (mCommonDialog != null && mCommonDialog.isShowing())
			mCommonDialog.dismiss();
		mCommonDialog = new LetvCommonDialog(context);
		mCommonDialog.setTitle(title);
		mCommonDialog.setContent(content.toString());
		mCommonDialog.setButtonText(leftText, rightText);
		if (leftListener != null)
			mCommonDialog.setLeftOnClickListener(leftListener);
		if (rightListener != null)
			mCommonDialog.setRightOnClickListener(rightListener);
		if (!context.isFinishing() && !context.isRestricted()) {
			mCommonDialog.show();
		}
	}

	/**
	 * 显示只有一个标题一个按钮的对话框
	 * 
	 * @param title
	 * @param centerText
	 */
	public static void showDialog(Activity context, CharSequence title,
			CharSequence centerText,
			DialogInterface.OnClickListener centerListener) {
		if (mCommonDialog != null && mCommonDialog.isShowing())
			mCommonDialog.dismiss();
		mCommonDialog = new LetvCommonDialog(context);
		mCommonDialog.setTitle(title);
		mCommonDialog.setButtonText(centerText);
		if (centerListener != null)
			mCommonDialog.setCenterOnClickListener(centerListener);
		if (!context.isFinishing() && !context.isRestricted()) {
			mCommonDialog.show();
		}
	}

	public static void call(Activity activity, int messageId, int yes, int no,
			DialogInterface.OnClickListener yesListener,
			DialogInterface.OnClickListener noListener) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setPositiveButton(yes, yesListener)
				.setNegativeButton(no, noListener).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}

	}

	//
	public static void call(Activity activity, int messageId, int yes, int no,
			DialogInterface.OnClickListener yesListener,
			DialogInterface.OnClickListener noListener, View view) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setView(view).setPositiveButton(yes, yesListener)
				.setNegativeButton(no, noListener).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}

	}

	public static boolean call(Activity activity, int messageId, int yes,
			int no, DialogInterface.OnClickListener yesListener,
			DialogInterface.OnClickListener noListener, View view,
			boolean cancelable) {

		if (activity == null) {
			return false;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setCancelable(cancelable).setView(view)
				.setPositiveButton(yes, yesListener)
				.setNegativeButton(no, noListener).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
			return true;
		}

		return false;
	}

	//
	public static void call(Context activity, String title, String message,
			int yes, int no, DialogInterface.OnClickListener yesListener,
			DialogInterface.OnClickListener noListener, boolean cancelable) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity).setTitle(title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(message)
				.setCancelable(cancelable).setPositiveButton(yes, yesListener)
				.setNegativeButton(no, noListener).create();
		if (activity instanceof Activity) {
			if (!((Activity) activity).isFinishing()
					&& !activity.isRestricted()) {
				dialog.show();
			}
		}
	}

	// public static void call(Context activity, String message,
	// DialogInterface.OnClickListener yesListener,
	// DialogInterface.OnClickListener noListener) {
	//
	// if (activity == null) {
	// return;
	// }
	//
	// Dialog dialog = new AlertDialog.Builder(activity)
	// .setTitle(R.string.dialog_default_title)
	// .setIcon(R.drawable.letv_dialog_icon).setMessage(message)
	// .setPositiveButton(R.string.dialog_default_ok, yesListener)
	// .setNegativeButton(R.string.dialog_default_no, noListener)
	// .create();
	//
	// if (activity instanceof Activity) {
	// if (!((Activity) activity).isFinishing()
	// && !activity.isRestricted()) {
	// try {
	// dialog.show();
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }
	// }
	//
	// }

	// public static void call(Context activity, String messageId, int yesId,
	// int noId, DialogInterface.OnClickListener yesListener,
	// DialogInterface.OnClickListener noListener) {
	//
	// if (activity == null) {
	// return;
	// }
	//
	// Dialog dialog = new AlertDialog.Builder(activity)
	// .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
	// .setPositiveButton(yesId, yesListener)
	// .setNegativeButton(noId, noListener).create();
	//
	// if (activity instanceof Activity) {
	// if (!((Activity) activity).isFinishing()
	// && !activity.isRestricted()) {
	// try {
	// dialog.show();
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }
	// }
	//
	// }

	// public static void call(Context context, int message, int yes, int no,
	// DialogInterface.OnClickListener yesListener,
	// DialogInterface.OnClickListener noListener, boolean cancelable) {
	//
	// if (context == null) {
	// return;
	// }
	//
	// Dialog dialog = new AlertDialog.Builder(context)
	// .setTitle(R.string.dialog_default_title)
	// .setIcon(R.drawable.letv_dialog_icon).setMessage(message)
	// .setCancelable(cancelable).setPositiveButton(yes, yesListener)
	// .setNegativeButton(no, noListener).create();
	// if (context instanceof Activity) {
	// if (!((Activity) context).isFinishing() && !context.isRestricted()) {
	// dialog.show();
	// }
	// }
	// }

	// public static void call(Context activity, int messageId, int yesId,
	// DialogInterface.OnClickListener yesListener,
	// DialogInterface.OnClickListener noListener, boolean cancelable) {
	// if (activity == null) {
	// return;
	// }
	//
	// Dialog dialog = new AlertDialog.Builder(activity)
	// .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
	// .setCancelable(cancelable)
	// .setPositiveButton(yesId, yesListener).create();
	// if (activity instanceof Activity) {
	// if (!((Activity) activity).isFinishing()
	// && !activity.isRestricted()) {
	// dialog.show();
	// }
	// }
	// }

	public static void call(Activity activity, int titleId, int messageId,
			DialogInterface.OnClickListener yes,
			DialogInterface.OnClickListener no) {
		try {
			if (activity == null) {
				return;
			}

			Dialog dialog = new AlertDialog.Builder(activity).setTitle(titleId)
					.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
					.setPositiveButton(R.string.dialog_default_ok, yes)
					.setNegativeButton(R.string.dialog_default_no, no).create();

			if (!activity.isFinishing() && !activity.isRestricted()) {
				dialog.show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	//
	public static void call(Activity activity, int messageId,
			DialogInterface.OnClickListener yes) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setPositiveButton(R.string.dialog_default_ok, yes).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}
	}

	public static void call(Activity activity, int title, int messageId,
			int yes, DialogInterface.OnClickListener yesListener,
			boolean cancelable) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity).setTitle(title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setCancelable(cancelable).setPositiveButton(yes, yesListener)
				.create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}
	}

	//
	public static void call(Activity activity, String message,
			DialogInterface.OnClickListener yes) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(message)
				.setPositiveButton(R.string.dialog_default_ok, yes).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}
	}

	//
	public static void call(Activity activity, String message,
			DialogInterface.OnClickListener yes, boolean cancelable) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setTitle(R.string.dialog_default_title)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(message)
				.setPositiveButton(R.string.dialog_default_ok, yes).create();
		dialog.setCancelable(cancelable);
		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}
	}

	//
	public static void call(Activity activity, int messageId, int yes, int no,
			DialogInterface.OnClickListener yesListener,
			DialogInterface.OnClickListener noListener, boolean cancelable) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity).setMessage(messageId)
				.setCancelable(cancelable).setPositiveButton(yes, yesListener)
				.setNegativeButton(no, noListener).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}
	}

	public static void call(Activity activity, String messageId,
			DialogInterface.OnClickListener yes,
			DialogInterface.OnClickListener no) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setPositiveButton(R.string.dialog_default_ok, yes)
				.setNegativeButton(R.string.dialog_default_no, no).create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}

	}

	public static void call(Activity activity, String messageId, int yesId,
			int noId, DialogInterface.OnClickListener yes,
			DialogInterface.OnClickListener no) {

		if (activity == null) {
			return;
		}

		Dialog dialog = new AlertDialog.Builder(activity)
				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
				.setPositiveButton(yesId, yes).setNegativeButton(noId, no)
				.create();

		if (!activity.isFinishing() && !activity.isRestricted()) {
			dialog.show();
		}

	}

	public static void call(Activity activity, int messageId, int yesId,
			DialogInterface.OnClickListener yes, boolean cancelable) {
		if (activity == null) {
			return;
		}

//		Dialog dialog = new AlertDialog.Builder(activity)
//				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
//				.setCancelable(cancelable).setPositiveButton(yesId, yes)
//				.create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//		}
		
		showDialog(activity, activity.getResources().getString(messageId),
				activity.getResources().getString(yesId), yes);
	}

	public static void call(Activity activity, int titleId, String messageId,
			int yesId, int noId, DialogInterface.OnClickListener yes,
			DialogInterface.OnClickListener no, boolean cancelable) {
		if (activity == null) {
			return;
		}

//		Dialog dialog = new AlertDialog.Builder(activity).setTitle(titleId)
//				.setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
//				.setCancelable(cancelable).setPositiveButton(yesId, yes)
//				.setNegativeButton(noId, no).create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//		}
		
		showDialog(activity, messageId, activity.getResources()
				.getString(yesId), activity.getResources().getString(noId),
				yes, no);
	}

	// ========================================================================================================
	// // -----------------------** 客户端dialog数据服务端化-----START
//	public static void callDialogMsgPositiveButton(Activity activity,
//			String msgId, DialogInterface.OnClickListener yes) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(msgId);
//		if (activity == null || dialogMsgByMsg == null) {
//			return;
//		}
//		Dialog dialog = new AlertDialog.Builder(activity)
//				.setTitle(
//						(!"".equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//								: activity
//										.getString(R.string.dialog_default_title))
//				.setIcon(R.drawable.letv_dialog_icon)
//				.setMessage(dialogMsgByMsg.message)
//				.setPositiveButton(R.string.dialog_default_ok, yes).create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//		}
//	}

	//
//	public static void callDialogMsgPositiveButton(Activity activity,
//			String msgId, int yes, DialogInterface.OnClickListener yesListener,
//			DialogInterface.OnKeyListener onKeyListener) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(msgId);
//		if (activity == null || dialogMsgByMsg == null) {
//			return;
//		}
//		Dialog dialog = new AlertDialog.Builder(activity)
//				.setTitle(
//						(!"".equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//								: activity
//										.getString(R.string.dialog_default_title))
//				.setOnKeyListener(onKeyListener)
//				.setIcon(R.drawable.letv_dialog_icon)
//				.setMessage(dialogMsgByMsg.message)
//				.setPositiveButton(yes, yesListener).create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//		}
//	}

	//
//	public static void callDialogMsgPosNeg(Activity activity, String msgId,
//			int yes, int no, DialogInterface.OnClickListener yesListener,
//			DialogInterface.OnClickListener noListener) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(msgId);
//
//		if (activity == null || dialogMsgByMsg == null) {
//			return;
//		}
//
//		Dialog dialog = new AlertDialog.Builder(activity)
//				.setTitle(
//						(!"".equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//								: activity
//										.getString(R.string.dialog_default_title))
//				.setIcon(R.drawable.letv_dialog_icon)
//				.setMessage(dialogMsgByMsg.message).setCancelable(false)
//				.setPositiveButton(yes, yesListener)
//				.setNegativeButton(no, noListener).create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//		}
//	}

//	public static boolean callDialogMsgPosNeg(Activity activity, String msgId,
//			int yes, int no, DialogInterface.OnClickListener yesListener,
//			DialogInterface.OnClickListener noListener, View view,
//			boolean cancelable) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(msgId);
//
//		if (activity == null || dialogMsgByMsg == null) {
//			return false;
//		}
//
//		Dialog dialog = new AlertDialog.Builder(activity)
//				.setTitle(
//						(!"".equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//								: activity
//										.getString(R.string.dialog_default_title))
//				.setView(view).setCancelable(cancelable)
//				.setIcon(R.drawable.letv_dialog_icon)
//				.setMessage(dialogMsgByMsg.message)
//				.setPositiveButton(yes, yesListener)
//				.setNegativeButton(no, noListener).create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//			return true;
//		}
//		return false;
//	}

	//
//	public static void callDialogMsgPosNegDefault(Activity activity,
//			String msgId, DialogInterface.OnClickListener yes,
//			DialogInterface.OnClickListener no) {
//
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(msgId);
//		if (activity == null || dialogMsgByMsg == null) {
//			return;
//		}
//		Dialog dialog = new AlertDialog.Builder(activity)
//				.setTitle(
//						(!"".equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//								: activity
//										.getString(R.string.dialog_default_title))
//				.setIcon(R.drawable.letv_dialog_icon)
//				.setMessage(dialogMsgByMsg.message)
//				.setPositiveButton(R.string.dialog_default_ok, yes)
//				.setNegativeButton(R.string.dialog_default_no, no).create();
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			try {
//				dialog.show();
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}
//
//	}

//	public static void callDialogMsgPosNegCancel(Activity activity,
//			String msgId, int yes, int no,
//			DialogInterface.OnClickListener yesListener,
//			DialogInterface.OnClickListener noListener, boolean cancelable,
//			String... messageWhichs) {
//		Dialog dialog = null;
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(msgId);
//		if (activity == null || dialogMsgByMsg == null) {
//			return;
//		}
//		if (dialogMsgByMsg.message.contains("%1$s")) {
//
//			dialog = new AlertDialog.Builder(activity)
//					.setTitle(
//							/* dialogMsgByMsg.title */(!""
//									.equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//									: activity
//											.getString(R.string.dialog_default_title))
//					.setMessage(
//							String.format(dialogMsgByMsg.message, messageWhichs))
//					.setCancelable(cancelable)
//					.setPositiveButton(yes, yesListener)
//					.setNegativeButton(no, noListener).create();
//		} else {
//			dialog = new AlertDialog.Builder(activity)
//					.setTitle(
//							/* dialogMsgByMsg.title */(!""
//									.equals(dialogMsgByMsg.title) && dialogMsgByMsg.title != null) ? dialogMsgByMsg.title
//									: activity
//											.getString(R.string.dialog_default_title))
//					.setMessage(dialogMsgByMsg.message)
//					.setCancelable(cancelable)
//					.setPositiveButton(yes, yesListener)
//					.setNegativeButton(no, noListener).create();
//
//		}
//
//		if (!activity.isFinishing() && !activity.isRestricted()) {
//			dialog.show();
//		}
//	}

	//
//	public static void notifyErrLong(Context context, String text) {
//		if (LetvApplication.getInstance() != null) {
//			mLetvToast = new LetvToast(LetvApplication.getInstance());
//			mLetvToast.setDuration(Toast.LENGTH_LONG);
//		}
//
//		mLetvToast.setErr(true);
//		mLetvToast.setMsg(text);
//		mLetvToast.show();
//		showToast(context, text, LetvApplication.getInstance() == null, false);
//	}



//	public static void notifyDBShortNormal(Context context, String toastMsgID) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(toastMsgID);
//		if (context == null || dialogMsgByMsg == null) {
//			return;
//		}
//		// if (mToast != null) {
//		// mToast.cancel();
//		// }
//		// if (LetvApplication.getInstance() != null) {
//		// mToast = Toast.makeText(LetvApplication.getInstance(),
//		// dialogMsgByMsg.message, Toast.LENGTH_LONG);
//		// }
//		// mToast.setText(dialogMsgByMsg.message);
//		// mToast.setGravity(Gravity.CENTER, 0, 0);
//		// mToast.setDuration(Toast.LENGTH_SHORT);
//		// mToast.show();
////		showToast(context, dialogMsgByMsg.message, false, false);
//		UIsPlayerLibs.showToast(context, dialogMsgByMsg.message);
//	}

//	public static void notifyDBShortNormal(Context context, String toastMsgID,
//			String msgTxt) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace().getDialogMsgByMsgId(toastMsgID);
//		if (context == null) {
//			return;
//		}
//
//		LogInfo.log("notifyDBShortNormal",
//				"notifyDBShortNormal dialogMsgByMsg : " + dialogMsgByMsg);
//
//		String txt = "";
//		if (dialogMsgByMsg == null && !TextUtils.isEmpty(msgTxt)) {
//			txt = msgTxt;
//		} else {
//			txt = dialogMsgByMsg.message;
//		}
//		// if (mToast != null) {
//		// mToast.cancel();
//		// }
//		// if (LetvApplication.getInstance() != null) {
//		// mToast = Toast.makeText(LetvApplication.getInstance(), txt,
//		// Toast.LENGTH_LONG);
//		// }
//		// mToast.setText(txt);
//		// mToast.setGravity(Gravity.CENTER, 0, 0);
//		// mToast.setDuration(Toast.LENGTH_SHORT);
//		// mToast.show();
//		// 原代码在application不为null时时间设置为长，目前统一改为短
////		showToast(context, txt, false, false);
//		UIsPlayerLibs.showToast(context, txt);
//	}

	/**
	 * 赞动画
	 *
	 * @param view
	 */
//	public static void animTop(Context context, final View view) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace()
//				.getDialogMsgByMsgId(DialogMsgConstantId.CONSTANT_100062);
//		// if (dialogMsgByMsg == null) {
//		// showToast(context, "已收藏到播放单");
//		// } else {
//		// showToast(context, dialogMsgByMsg.message);
//		// }
//
//		if (view != null) {
//			if (null != view.getAnimation() && !view.getAnimation().hasEnded()) {
//				return;
//			}
//			view.post(new Runnable() {
//				@Override
//				public void run() {
//					animCollection(view, collectionAniScaleRec, 0);
//				}
//			});
//		}
//	}

	/**
	 * 收藏渐变规则
	 */
	private static float[] collectionAniScaleRec = new float[] { 1.0f, 0.6f,
			1.5f, 0.8f, 1.0f };

	private static float[] unConllectionAniScalRec = new float[] { 1.0f, 0.6f,
			1.5f, 0.6f, 1.0f };
	/**
	 * 渐变率(必须要能被scaleSize数组的相邻两个数值之差整除)
	 */
	private static float scaleRate = 0.1f;
	/**
	 * 动画总执行时间ms(由于实际几个Animation之间执行回调需要时间，所以实际总动画时间会比这个时间长)
	 */
	private static final int animTotallTime = 220;

	/**
	 * 收藏动画
	 * 
	 * @param view
	 */
	public static void animCollection(Context context, final View view) {
		// modified by zengsonghai 2014/7/6 --- start 收藏不成功不应该弹出提示
		// MessageBean dialogMsgByMsg =
		// DBManager.getInstance().getDialogMsgTrace().getDialogMsgByMsgId(DialogMsgConstantId.CONSTANT_20009);
		// if (dialogMsgByMsg == null) {
		// showToast(context, "已收藏到播放单");
		// } else {
		// showToast(context, dialogMsgByMsg.message);
		// }
		// modified by zengsonghai 2014/7/6 --- end 收藏不成功不应该弹出提示

		if (view != null) {
			if (null != view.getAnimation() && !view.getAnimation().hasEnded()) {
				return;
			}
			view.post(new Runnable() {
				@Override
				public void run() {
					animCollection(view, collectionAniScaleRec, 0);
				}
			});
		}
	}

	/**
	 * 取消收藏
	 * 
	 * @param view
	 */
//	public static void animUncollection(Context context, final View view) {
//		MessageBean dialogMsgByMsg = DBManager.getInstance()
//				.getDialogMsgTrace()
//				.getDialogMsgByMsgId(DialogMsgConstantId.CONSTANT_20010);
//		if (dialogMsgByMsg == null) {
//			UIs.showPopWin(view, R.layout.layout_popwindow, "已取消收藏", true);
//		} else {
//			UIs.showPopWin(view, R.layout.layout_popwindow,
//					dialogMsgByMsg.message, true);
//		}
//
//		if (view != null) {
//			if (null != view.getAnimation() && !view.getAnimation().hasEnded()) {
//				return;
//			}
//			view.post(new Runnable() {
//
//				@Override
//				public void run() {
//					animCollection(view, unConllectionAniScalRec, 0);
//				}
//			});
//		}
//	}

	/**
	 * 收藏/取消收藏 动画实际逻辑
	 */
	private static void animCollection(final View view,
			final float[] aniScaleRec, final int index) {
		animFrames(view, index, aniScaleRec, new Runnable() {

			@Override
			public void run() {
				if (index + 1 < aniScaleRec.length - 1) {
					animCollection(view, aniScaleRec, index + 1);
				}
			}
		});

	}

	/**
	 * 收藏view的每次变换动画逻辑
	 * 
	 * @param view
	 * @param index
	 * @param animFrameTime
	 * @param width
	 * @param height
	 * @param callback
	 *            动画执行完成回调
	 */
	private static void animFrames(final View view, final int index,
			float[] aniScaleRec, final Runnable callback) {
		/**
		 * 总帧数
		 */
		float totalFrame = 0;
		for (int i = 0; i < aniScaleRec.length - 1; i++) {
			totalFrame += Math.abs(aniScaleRec[i + 1] - aniScaleRec[i]);
		}
		/**
		 * 执行每一帧切换的时间
		 */
		final int animFrameTime = animTotallTime
				/ ((int) (totalFrame / scaleRate));
		float animEnd = aniScaleRec[index + 1];
		float animStart = aniScaleRec[index];
		final int scaleCount = Math
				.abs(((int) (animEnd * 100) - (int) (animStart * 100))
						/ ((int) (scaleRate * 100)));
		int duration = scaleCount * animFrameTime;
		ScaleAnimation sa = new ScaleAnimation(animStart, animEnd, animStart,
				animEnd, Animation.RELATIVE_TO_SELF, 0.5f,
				Animation.RELATIVE_TO_SELF, 0.5f);
		sa.setFillAfter(true);
		sa.setDuration(duration);
		sa.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				callback.run();
			}
		});
		view.startAnimation(sa);
	}

	/**
	 * 头像右上角收藏泡泡 动画
	 */
	public static void animCollectionPop(final View view) {
		if (view != null) {
			view.setVisibility(View.VISIBLE);
			ScaleAnimation sa = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
					Animation.RELATIVE_TO_SELF, 0.0f,
					Animation.RELATIVE_TO_SELF, 1.0f);
			sa.setDuration(400);
			view.startAnimation(sa);
		}
	}

	// public static void deleteShortCutIcon(Context ctx, int appId) {
	// Intent intent = new
	// Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
	// // 获取当前应用名称
	// String title = null;
	// try {
	// final PackageManager pm = ctx.getPackageManager();
	// title =
	// pm.getApplicationLabel(pm.getApplicationInfo(ctx.getPackageName(),
	// PackageManager.GET_META_DATA))
	// .toString();
	// } catch (Exception e) {
	// }
	// intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
	// // 要删除的应用程序的ComponentName，即应用程序包名+activity的名字
	// ComponentName comp = new ComponentName(ctx.getPackageName(), title);
	// intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
	// new Intent().setComponent(comp).setAction("android.intent.action.MAIN"));
	// ctx.sendBroadcast(intent);
	// }
	//
	// /**
	// * 创建桌面快捷方式
	// *
	// * @param ctx
	// */
	// public static void createShortCutIcon(Context ctx) {
	// // 删除老的乐视影视快捷方式
	// deleteShortCutIcon(ctx, R.string.old_app_name);
	// deleteShortCutIcon(ctx, R.string.app_name);
	// if (!IfaddShortCut(ctx, R.string.app_name) &&
	// !PreferencesManager.getInstance().getShortCutIcon()) {
	// Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
	// shortcutIntent.setClass(ctx, MainActivity.class);
	// shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
	// shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	// shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
	//
	// Intent intent = new Intent();
	// intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
	// intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
	// ctx.getResources().getString(R.string.app_name));
	// intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
	// Intent.ShortcutIconResource.fromContext(ctx.getApplicationContext(),
	// R.drawable.letv_icon));
	// intent.putExtra("duplicate", false);
	// intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
	// ctx.sendBroadcast(intent);
	// PreferencesManager.getInstance().setShortCutIcon(true);
	// }
	// }
	//
	// /**
	// * 创建桌面搜索快捷方式
	// *
	// * @param ctx
	// */
	// public static void createSearchShortCutIcon(Context ctx,String appName) {
	//
	// // 删除老的乐视影视快捷方式
	// deleteShortCutIcon(ctx, R.string.old_app_name);
	// deleteShortCutIcon(ctx, R.string.app_name);
	// if (!IfaddShortCut(ctx, R.string.letv_search_name)&& !installApp(ctx,
	// packageSearchName)) {
	// Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
	// shortcutIntent.setClassName(ctx,
	// "com.letv.android.client.ui.impl.SearchMainActivity");
	// // shortcutIntent.setClass(ctx, SearchMainActivity.class);
	// shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
	// shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	// shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
	// shortcutIntent.putExtra("source", "lesou");
	//
	// Intent intent = new Intent();
	// intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
	// intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
	// intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
	// Intent.ShortcutIconResource.fromContext(ctx.getApplicationContext(),
	// R.drawable.letv_search_icon));
	// intent.putExtra("duplicate", false);
	// intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
	// ctx.sendBroadcast(intent);
	//
	// PreferencesManager.getInstance().setSearchShortcut(false);
	// }
	// }
	//
	// //
	// public static boolean installApp(Context context, String packageName) {
	//
	// PackageManager packageManager = context.getPackageManager();
	// try {
	// PackageInfo pInfo = packageManager.getPackageInfo(packageName,
	// PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
	// //判断是否获取到了对应的包名信息
	// if(pInfo!=null){
	// return true;
	// }
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// return false;
	// }
	// /**
	// * 是否有快捷方式
	// * */
	// public static boolean IfaddShortCut(Context ctx, int appId) {
	// boolean isInstallShortcut = false;
	//
	// // 由于系统差异，uriStr在不同机型上的launcher有所差异
	// final String uriStr1 =
	// "content://com.android.launcher.settings/favorites?notify=true";
	// final String uriStr2 =
	// "content://com.android.launcher2.settings/favorites?notify=true";
	// Cursor cursor = null;
	// if (VERSION.SDK_INT >= 8) {
	// cursor = getCursorByUri(ctx, uriStr2, appId);
	// } else {
	// cursor = getCursorByUri(ctx, uriStr1, appId);
	// }
	// isInstallShortcut = (cursor != null && cursor.getCount() > 0);
	// LogInfo.log("main", ctx.getString(appId) + " has  shortcut =" +
	// isInstallShortcut);
	// if (cursor != null) {
	// cursor.close();
	// }
	// return isInstallShortcut;
	// }
	// =============================================================================
	/**
	 * 删除桌面快捷方式
	 *
	 */
	public static void deleteShortCutIcon(Context ctx, int string_app_name,
			String className) {
		Intent shortcutIntent = null;
		shortcutIntent = new Intent(Intent.ACTION_MAIN);
		shortcutIntent.setClassName(ctx, className);
		shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
		shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

		Intent delShortcut = new Intent();
		delShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
		delShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, ctx.getResources()
				.getString(string_app_name));
		delShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
		ctx.sendBroadcast(delShortcut);
	}

	/**
	 * 创建桌面快捷方式
	 *
	 * */
	public static void createShortCutIcon(Context ctx, int string_app_name,
			int drawbale_letv_icon, Class className) {
		Intent shortcutIntent = null;
		shortcutIntent = new Intent(Intent.ACTION_MAIN);
		shortcutIntent.setClass(ctx, className);
		shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
		shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
		shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

		final Intent intent = new Intent();
		intent.putExtra("duplicate", false);
		intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
		intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ctx.getResources()
				.getString(string_app_name));
		Log.v("LM",
				"name  " + LetvUtil.getBrandName() + "   "
						+ LetvUtil.getDeviceName());
		if (LetvUtil.getBrandName().equalsIgnoreCase("coolpad")) {
			if (LetvUtil.getDeviceName().contains("8297")
					|| LetvUtil.getDeviceName().contains("9976")) {
				intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
						getNormalBitMap(ctx, drawbale_letv_icon));
			} else {
				intent.putExtra(
						Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
						Intent.ShortcutIconResource.fromContext(
								ctx.getApplicationContext(), drawbale_letv_icon));
			}
		} else if (LetvUtil.getBrandName().equalsIgnoreCase("huawei")) {
			if (LetvUtil.getDeviceName().contains("P7")
					|| LetvUtil.getDeviceName().contains("p7")
					|| LetvUtil.getDeviceName().contains("p6")
					|| LetvUtil.getDeviceName().contains("P6")
					|| LetvUtil.getDeviceName().contains("H30-U10")) {
				intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
						getNormalBitMapForP7(ctx, drawbale_letv_icon));
			} else {
				intent.putExtra(
						Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
						Intent.ShortcutIconResource.fromContext(
								ctx.getApplicationContext(), drawbale_letv_icon));
			}
		} else if (LetvUtil.getBrandName().equalsIgnoreCase("oppo")) {
			if (LetvUtil.getDeviceName().contains("X909T")) {
				intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
						getNormalBitMapForP7(ctx, drawbale_letv_icon));
			} else {
				intent.putExtra(
						Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
						Intent.ShortcutIconResource.fromContext(
								ctx.getApplicationContext(), drawbale_letv_icon));
			}
		} else if (LetvUtil.getBrandName().equalsIgnoreCase("samsung")) {
			if (LetvUtil.getDeviceName().contains("I9100")) {
				intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
						getNormalBitMapForP7(ctx, drawbale_letv_icon));
			} else {
				intent.putExtra(
						Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
						Intent.ShortcutIconResource.fromContext(
								ctx.getApplicationContext(), drawbale_letv_icon));
			}
		} else {
			intent.putExtra(
					Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
					Intent.ShortcutIconResource.fromContext(
							ctx.getApplicationContext(), drawbale_letv_icon));
		}
		intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		ctx.sendBroadcast(intent);
	}

	/**
	 * 解决乐看搜索和乐视视频快捷方式icon相同问题
	 * 
	 * @param context
	 * @param id
	 * @return
	 */
	private static Bitmap getNormalBitMapForP7(Context context, int id) {
		Bitmap bitMap = ((BitmapDrawable) context.getResources()
				.getDrawable(id)).getBitmap();
		int bmpWidth = bitMap.getWidth();
		int bmpHeight = bitMap.getHeight();
		int sWidth = 144;
		int sHeight = 144;
		float scaleWidth = (float) sWidth / bmpWidth;
		float scaleHeight = (float) sHeight / bmpHeight;
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		Bitmap resizeBitmap = Bitmap.createBitmap(bitMap, 0, 0, bmpWidth,
				bmpHeight, matrix, false);
		return resizeBitmap;
	}

	private static Bitmap getNormalBitMap(Context context, int id) {
		Bitmap bitMap = ((BitmapDrawable) context.getResources()
				.getDrawable(id)).getBitmap();
		return bitMap;
	}

	// /**
	// * 加载资源文件图片
	// * */
	// public static Drawable loadResourcesDrawable(Context context,
	// int resourcesId) {
	// return Drawable.createFromStream(context.getResources()
	// .openRawResource(resourcesId), null);
	// }

	/**
	 * 加载资源文件图片
	 * */
	public static Bitmap loadResourcesBitmap(Context context, int resourcesId) {
		return BitmapFactory.decodeStream(context.getResources()
				.openRawResource(resourcesId));
	}

	/**
	 * 回收资源文件图片
	 * */
	public static void recycleBitmap(Bitmap bitmap) {
		if (bitmap != null && !bitmap.isRecycled()) {
			bitmap.recycle();
		}
		bitmap = null;
	}

	/**
	 * 回收ImageView及其image bitmap
	 * */
	// public static void recycleImageView(ImageView imageView) {
	// if (null != imageView) {
	// BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView
	// .getDrawable();
	// Bitmap bitmap = null;
	// if (null != bitmapDrawable) {
	// bitmap = bitmapDrawable.getBitmap();
	// }
	// if (bitmap != null && !bitmap.isRecycled()) {
	// bitmap.recycle();
	// }
	// bitmap = null;
	// imageView = null;
	// }
	// }

	/**
	 * 加载资源文件图片
	 * */
	// public static void recycleDrawable(Drawable drawable) {
	// if (drawable != null) {
	// drawable.setCallback(null);
	// }
	// drawable = null;
	// }

	public static Bitmap resizeBitmap(Bitmap bitmap, int width, int height) {
		final Bitmap b = Bitmap.createBitmap(width, height, Config.RGB_565);
		final Canvas canvas = new Canvas(b);
		Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
		Rect dst = new Rect(0, 0, width, height);
		Paint paint = new Paint();
		canvas.drawBitmap(bitmap, src, dst, paint);
		return b;
	}

	/**
	 * 取消activity跳转动画
	 * 
	 * @param activity
	 */
	public static void overridePendingTransition(Activity activity) {
		Class clazz = activity.getClass();
		try {
			java.lang.reflect.Method overPendingMethod = clazz.getMethod("overridePendingTransition", int.class, int.class);
			(overPendingMethod).invoke(activity, 0, 0);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
}

